﻿;Void BilinearQuadARGB32_V4(
;                Pixel* dst, Pixel* src, Int32 srcPitch,
;                UInt32 srcx_16, UInt32 xrIntFloat_16, UInt32 v_8);

;R0 = dst
;R1 = src
;R2 = srcPitch
;R3 = srcx_16
;R4 = v_8
;R5 = u_8
;R6 = pm3_8
;LR = 0x00FF00FF

        AREA sample, CODE, READONLY
   EXPORT  BilinearQuadARGB32_V4
BilinearQuadARGB32_V4


	STMFD	SP!, {R4-R12, LR}
	LDR	    R4, [SP, #44]               ;R4 = v_8

    MOV     R7, R3, LSR #16             ;R7: srcx_16>>16
    ADD     R1, R1, R7, LSL #2          ;R1: src += (srcx_16>>16)

	MOV	    LR, #16711680
	ADD	    LR, LR, #255                ;LR: 00FF00FF

;;;;;;;;;;;pixel1
	MOV	    R5, R3, LSR #8              ;R5: (srcx_16 & 0xFFFF)
    AND	    R5, R5, #255                ;R5: u_8 = (srcx_16 & 0xFFFF)>>8;

    MUL     R6, R5, R4                  ;R6: (u_8 * v_8)
	MOV	    R6, R6, LSR #8              ;R6: pm3_8 = (u_8 * v_8)>>8


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color0[0]
	LDR	    R8, [R1], #4                ;R8: R8= color0[0], R1: src = src + 4

    RSB     R7, R4, #256                ;R7: 256 - v_8
    SUB     R7, R7, R5                  ;R7: 256 - v_8 - u_8
    ADD     R7, R7, R6                  ;R7: pm0_8 = 256 - v_8 - u_8 + pm3_8

	AND	    R9, LR, R8, LSR #8          ;AG
	MUL	    R11, R9, R7                 ;Sum_RB = RB * pm3_8;

	AND	    R10, R8, LR                 ;RB

    LDR     R8, [R1], R2                ;color0[1] ; src = (UInt8*)src + srcPitch + 4

	MUL	    R12, R10, R7                ;Sum_AG = AG * pm3_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color0[1]
    SUB     R7, R5, R6                  ;R5: pm2_8 = u_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R7, R11            ;Sum_RB += RB * pm2_8;

	AND	    R10, R8, LR                 ;RB

	LDR	    R8, [R1], #-4               ;R8: color1[1],  src = (UInt8*)src + srcPitch

	MLA	    R12, R10, R7, R12           ;Sum_AG += AG * pm2_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color1[1]
	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11            ;Sum_RB += (RB * pm3_8);

	AND	    R10, R8, LR                 ;RB

	LDR	    R8, [R1], -R2               ;color1[0], R1 = src

	MLA	    R12, R10, R6, R12           ;Sum_AG += (AG * pm3_8);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color1[0]

    SUB     R6, R4, R6                  ;UInt8 pm1_8 = v_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12


;;;;;;;;/
	AND	    R11, LR, R11, LSR #8        ;Sum_AG = (*color>>8) & 0x00FF00FF;
	AND	    R12, LR, R12, LSR #8        ;Sum_RB = (*color) & 0x00FF00FF;
	ORR	    R12, R12, R11, LSL #8       ;ϲ

	STR	    R12, [R0], #4

	LDR	    R7, [SP, #40]               ;R7 = xrIntFloat_16

    MOV     R9, R3, LSR#16              ;R7: srcx_16>>16
    SUB     R1, R1, R9, LSL#2           ;R1: src += (srcx_16>>16)



;
;;;;;;;;;;/pixel2
    ADD     R3, R3, R7                  ;R3: srcx_16 += xrIntFloat_16;
    MOV     R7, R3, LSR #16             ;R7: srcx_16>>16
    ADD     R1, R1, R7, LSL #2          ;R1: src += (srcx_16>>16)


	MOV	    R5, R3, LSR #8              ;R5: (srcx_16 & 0xFFFF)
    AND	    R5, R5, #255                ;R5: u_8 = (srcx_16 & 0xFFFF)>>8;

    MUL     R6, R5, R4                  ;R6: (u_8 * v_8)
	MOV	    R6, R6, LSR #8              ;R6: pm3_8 = (u_8 * v_8)>>8


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color0[0]
	LDR	    R8, [R1], #4                ;R8: r8= color0[0], R1: src = src + 4

    RSB     R7, R4, #256                ;R7: 256 - v_8
    SUB     R7, R7, R5                  ;R7: 256 - v_8 - u_8
    ADD     R7, R7, R6                  ;R7: pm0_8 = 256 - v_8 - u_8 + pm3_8

	AND	    R9, LR, R8, LSR #8          ;AG
	MUL	    R11, R9, R7                 ;Sum_RB = RB * pm3_8;

	AND	    R10, R8, LR                 ;RB

    LDR     R8, [R1], R2                ;color0[1] ; src = (UInt8*)src + srcPitch + 4

	MUL	    R12, R10, R7                ;Sum_AG = AG * pm3_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color0[1]
    SUB     R7, R5, R6                  ;R5: pm2_8 = u_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R7, R11            ;Sum_RB += RB * pm2_8;

	AND	    R10, R8, LR                 ;RB

	LDR	    R8, [R1], #-4               ;R8: color1[1],  src = (UInt8*)src + srcPitch

	MLA	    R12, R10, R7, R12           ;Sum_AG += AG * pm2_8;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color1[1]


	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11            ;Sum_RB += (RB * pm3_8);

	AND	    R10, R8, LR                 ;RB

	LDR	    R8, [R1], -R2               ;color1[0], R1 = src

	MLA	    R12, R10, R6, R12           ;Sum_AG += (AG * pm3_8);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color1[0]

    SUB     R6, R4, R6                  ;UInt8 pm1_8 = v_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12


;;;;;;;;/
	AND	    R11, LR, R11, LSR #8        ;Sum_AG = (*color>>8) & 0x00FF00FF;
	AND	    R12, LR, R12, LSR #8        ;Sum_RB = (*color) & 0x00FF00FF;
	ORR	    R12, R12, R11, LSL #8       ;ϲ

	LDR	    R7, [SP, #40]               ;R7 = xrIntFloat_16

	STR	    R12, [R0], #4

    MOV     R9, R3, LSR #16              ;R7:
    SUB     R1, R1, R9, LSL #2           ;R1: src += (srcx_16>>16)


;.long 0xe7fddefe
;;
;;;;;;;;;pixel 3
;;
    ADD     R3, R3, R7                  ;R3: srcx_16 += xrIntFloat_16;
    MOV     R7, R3, LSR #16             ;R7: srcx_16>>16
    ADD     R1, R1, R7, LSL #2          ;R1: src += (srcx_16>>16)

	MOV	    R5, R3, LSR #8              ;R5: (srcx_16 & 0xFFFF)
    AND	    R5, R5, #255                ;R5: u_8 = (srcx_16 & 0xFFFF)>>8;

    MUL     R6, R5, R4                  ;R6: (u_8 * v_8)
	MOV	    R6, R6, LSR #8              ;R6: pm3_8 = (u_8 * v_8)>>8


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color0[0]
	LDR	    R8, [R1], #4                ;R8: r8= color0[0], R1: src = src + 4

    RSB     R7, R4, #256                ;R7: 256 - v_8
    SUB     R7, R7, R5                  ;R7: 256 - v_8 - u_8
    ADD     R7, R7, R6                  ;R7: pm0_8 = 256 - v_8 - u_8 + pm3_8

	AND	    R9, LR, R8, LSR #8          ;AG
	MUL	    R11, R9, R7                 ;Sum_RB = RB * pm3_8;

	AND	    R10, R8, LR                 ;RB
	MUL	    R12, R10, R7                ;Sum_AG = AG * pm3_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color0[1]
    LDR     R8, [R1], R2                ;color0[1] ; src = (UInt8*)src + srcPitch + 4
    SUB     R7, R5, R6                  ;R5: pm2_8 = u_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R7, R11            ;Sum_RB += RB * pm2_8;

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R7, R12           ;Sum_AG += AG * pm2_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color1[1]
	LDR	    R8, [R1], #-4               ;R8: color1[1],  src = (UInt8*)src + srcPitch

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11            ;Sum_RB += (RB * pm3_8);

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12           ;Sum_AG += (AG * pm3_8);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color1[0]
	LDR	    R8, [R1], -R2               ;color1[0], R1 = src
    SUB     R6, R4, R6                  ;UInt8 pm1_8 = v_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12

;;;;;;;;/

	AND	    R11, LR, R11, LSR #8        ;Sum_AG = (*color>>8) & 0x00FF00FF;
	AND	    R12, LR, R12, LSR #8        ;Sum_RB = (*color) & 0x00FF00FF;
	ORR	    R12, R12, R11, LSL #8       ;ϲ

	LDR	    R7, [SP, #40]               ;R7 = xrIntFloat_16

	STR	    R12, [R0], #4

    MOV     R9, R3, LSR #16             ;R7:
    SUB     R1, R1, R9, LSL #2          ;R1: src += (srcx_16>>16)



;;;;;;;;/Pixel 4
    ADD     R3, R3, R7                  ;R3: srcx_16 += xrIntFloat_16;
    MOV     R7, R3, LSR #16             ;R7: srcx_16>>16
    ADD     R1, R1, R7, LSL #2          ;R1: src += (srcx_16>>16)

	MOV	    R5, R3, LSR #8              ;R5: (srcx_16 & 0xFFFF)
    AND	    R5, R5, #255                ;R5: u_8 = (srcx_16 & 0xFFFF)>>8;

    MUL     R6, R5, R4                  ;R6: (u_8 * v_8)
	MOV	    R6, R6, LSR #8              ;R6: pm3_8 = (u_8 * v_8)>>8


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color0[0]
	LDR	    R8, [R1], #4                ;R8: r8= color0[0], R1: src = src + 4

    RSB     R7, R4, #256                ;R7: 256 - v_8
    SUB     R7, R7, R5                  ;R7: 256 - v_8 - u_8
    ADD     R7, R7, R6                  ;R7: pm0_8 = 256 - v_8 - u_8 + pm3_8

	AND	    R9, LR, R8, LSR #8          ;AG
	MUL	    R11, R9, R7                 ;Sum_RB = RB * pm3_8;

	AND	    R10, R8, LR                 ;RB
	MUL	    R12, R10, R7                ;Sum_AG = AG * pm3_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color0[1]
    LDR     R8, [R1], R2                ;color0[1] ; src = (UInt8*)src + srcPitch + 4
    SUB     R7, R5, R6                  ;R5: pm2_8 = u_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R7, R11            ;Sum_RB += RB * pm2_8;

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R7, R12           ;Sum_AG += AG * pm2_8;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;color1[1]
	LDR	    R8, [R1], #-4               ;R8: color1[1],  src = (UInt8*)src + srcPitch

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11            ;Sum_RB += (RB * pm3_8);

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12           ;Sum_AG += (AG * pm3_8);


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;/color1[0]
	LDR	    R8, [R1], -R2               ;color1[0], R1 = src
    SUB     R6, R4, R6                  ;UInt8 pm1_8 = v_8 - pm3_8;

	AND	    R9, LR, R8, LSR #8          ;AG
	MLA	    R11, R9, R6, R11

	AND	    R10, R8, LR                 ;RB
	MLA	    R12, R10, R6, R12


;;;;;;;;/
	AND	    R11, LR, R11, LSR #8        ;Sum_AG = (*color>>8) & 0x00FF00FF;
	AND	    R12, LR, R12, LSR #8        ;Sum_RB = (*color) & 0x00FF00FF;
	ORR	    R12, R12, R11, LSL #8       ;ϲ

	STR	    R12, [R0]

BilinearQuadRGB24_V4_End

	LDMFD	SP!, {R4-R12, PC}



    END